const ROLES = {
  ADMIN: 1,
  MANAGER_DEPART: 2,
  MANAGER_PROJECT: 3,
  MEMBER: 4
}
module.exports = {

  title: '配置管理平台',

  /**
   * 分页参数
   */
  pageParams: {
    pageSizes: [20, 50, 100, 200, 500], // 分页下拉框
    pageSize: 20, // 分页默认条数
    currentPage: 1, // 默认页数
    total: 1 // 默认总条数
  },
  ToutiaoAuthUrl: 'https://ad.oceanengine.com/openapi/audit/oauth.html?app_id=1673108353772574&state=your_custom_params&scope=%5B2%2C3%2C4%2C5%2C8%2C9%2C10%2C11%2C12%2C14%5D&material_auth=1&redirect_uri=http%3A%2F%2Fad.adjdds.com%2Fapi%2Ftoutiao_callback&rid=tg3rp6qs1kb',
  dataTypes: [{
    id: 'cost',
    name: '消耗'
  },
  {
    id: 'clickprice',
    name: '点击单价'
  },
  {
    id: 'clickrate',
    name: '点击率'
  },
  {
    id: 'change',
    name: '转化数'
  },
  {
    id: 'a',
    name: '转化成本'
  },
  {
    id: 'b',
    name: '转化率'
  },
  {
    id: 'feiyu',
    name: '飞鱼线索量'
  },
  {
    id: 'feiyuconst',
    name: '飞鱼成本'
  }
  ],
  // 推广目的
  landing_types: [
    {
      id: 'LINK',
      name: '销售线索收集',
      disabled:false
    },
    {
      id: 'APP',
      name: '应用推广',
      disabled:true
    },
    {
      id: 'DPA',
      name: '产品目录推广',
      disabled:true
    },
    {
      id: 'GOODS',
      name: '商品推广（鲁班）',
      disabled:true
    },
    {
      id: 'STORE',
      name: '门店推广',
      disabled:true
    },
    {
      id: 'AWEME',
      name: '抖音号推广',
      disabled:true
    },
    {
      id: 'SHOP',
      name: '电商店铺推广',
      disabled:true
    },
  ],
  audience_config: {
      age:{
          '18~23': 'AGE_BETWEEN_18_23',
          '24~30': 'AGE_BETWEEN_24_30',
          '31~40': 'AGE_BETWEEN_31_40',
          '41~49': 'AGE_BETWEEN_41_49',
          '50+': 'AGE_ABOVE_50',
      },
      platform: {
          'IOS': 'IOS',
          'Android': 'ANDROID',
          'PC': 'PC',
      },
      ac: {
          'WIFI': 'WIFI',
          '2G': '2G',
          '3G': '3G',
          '4G': '4G',
      },
      carrier: {
          '移动': 'MOBILE',
          '联通': 'UNICOM',
          '电信': 'TELCOM',
      },
      activate_type: {
          '一个月以内': 'WITH_IN_A_MONTH',
          '一个月到三个月': 'ONE_MONTH_2_THREE_MONTH',
          '三个月以上': 'THREE_MONTH_EAILIER',
      },
      article_category: {
          '娱乐':'ENTERTAINMENT',
          '社会':'SOCIETY',
          '汽车':'CARS',
          '国际':'INTERNATIONAL',
          '历史':'HISTORY',
          '体育':'SPORTS',
          '健康':'HEALTH',
          '军事':'MILITARY',
          '情感':'EMOTION',
          '时尚':'FASHION',
          '育儿':'PARENTING',
          '财经':'FINANCE',
          '搞笑':'AMUSEMENT',
          '数码':'DIGITAL',
          '探索':'EXPLORE',
          '旅游':'TRAVEL',
          '星座':'CONSTELLATION',
          '故事':'STORIES',
          '科技':'TECHNOLOGY',
          '美食':'GOURMET',
          '文化':'CULTURE',
          '家居':'HOME',
          '电影':'MOVIE',
          '宠物':'PETS',
          '游戏':'GAMES',
          '瘦身':'WEIGHT_LOSING',
          '奇葩':'FREAK',
          '教育':'EDUCATION',
          '房产':'ESTATE',
          '科学':'SCIENCE',
          '摄影':'PHOTOGRAPHY',
          '养生':'REGIMEN',
          '美文':'ESSAY',
          '收藏':'COLLECTION',
          '动漫':'ANIMATION',
          '漫画':'COMICS',
          '小窍门':'TIPS',
          '设计':'DESIGN',
          '本地':'LOCAL',
          '法制':'LAWS',
          '政务':'GOVERNMENT',
          '商业':'BUSINESS',
          '职场':'WORKPLACE',
          '辟谣':'RUMOR_CRACKER',
          '毕业生':'GRADUATES',
      },
      device_brand: {
          '荣耀':'HONOR',
          '苹果':'APPLE',
          '华为':'HUAWEI',
          '小米':'XIAOMI',
          '三星':'SAMSUNG',
          'OPPO':'OPPO',
          'VIVO':'VIVO',
          '魅族':'MEIZU',
          '金立':'GIONEE',
          '酷派':'COOLPAD',
          '联想':'LENOVO',
          '乐视':'LETV',
          '中兴':'ZTE',
          '中国移动':'CHINAMOBILE',
          'HTC':'HTC',
          '小辣椒':'PEPPER',
          '努比亚':'NUBIA',
          '海信':'HISENSE',
          '奇酷':'QIKU',
          'TCL':'TCL',
          '索尼':'SONY',
          '锤子手机':'SMARTISAN',
          '360手机':'360',
          '一加手机':'ONEPLUS',
          'LG':'LG',
          '摩托罗拉':'MOTO',
          '诺基亚':'NOKIA',
          '谷歌':'GOOGLE',
      },
      hide_if_converted: {
         '不限': 'NO_EXCLUDE',
         '广告计划': 'AD',
         '广告组': 'CAMPAIGN',
         '广告账户': 'ADVERTISER',
         '公司账户': 'CUSTOMER',
      },
      smart_bid_type: {
        '手动': 'SMART_BID_CUSTOM',
        '自动': 'SMART_BID_CONSERVATIVE',
      },
      flow_control_mode: {
        '优先跑量': 'FLOW_CONTROL_MODE_FAST',
        '均衡投放': 'FLOW_CONTROL_MODE_BALANCE',
        '优先低成本': 'FLOW_CONTROL_MODE_SMOOTH',
      },
      budget_mode: {
        '日预算': 'BUDGET_MODE_DAY',
        '总预算': 'BUDGET_MODE_TOTAL',
      },
      pricing: {
        '按展示付费(oCPM)': 'PRICING_OCPM',
        '按转化付费(CPA)': 'PRICING_CPA',
      }
  },
  validatePassword: (rule, value, callback) => {
    /*eslint no-useless-escape: "error"*/
    if (value == '') {
      callback(new Error('请输入密码'))
      return
    }
    var myreg = /^[0-9A-Za-z]+$/
    if (!myreg.test(value)) {
      callback(new Error('密码必须为字母或数字'))
      return
    }
    if (value.length < 6 || value.length > 20) {
      callback(new Error('密码长度在 6 到 20 个字符'))
      return
    }
    callback()
  },
  parseTime: (time, cFormat) => {
    // if (arguments.length === 0) {
    //   return null
    // }
    const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
    let date
    if (typeof time === 'object') {
      date = time
    } else {
      if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
        time = parseInt(time)
      }
      if ((typeof time === 'number') && (time.toString().length === 10)) {
        time = time * 1000
      }
      date = new Date(time)
    }
    const formatObj = {
      y: date.getFullYear(),
      m: date.getMonth() + 1,
      d: date.getDate(),
      h: date.getHours(),
      i: date.getMinutes(),
      s: date.getSeconds(),
      a: date.getDay()
    }
    const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
      const value = formatObj[key]
      // Note: getDay() returns 0 on Sunday
      if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
      return value.toString().padStart(2, '0')
    })
    return time_str
  },
  checkRole(id_role) {
    // 1 管理员 2负责人 3员工
    return id_role
  },
  isAdmin(id_role) {
    return id_role == ROLES.ADMIN
  },
  isMember(id_role) {
    return id_role == ROLES.MEMBER
  },
  parseObject(obj, data) {
    for (const k in obj) {
      if (Object.prototype.hasOwnProperty.call(data, k)) {
        // console.log('k', k)
        // if (k == 'launch_price') {
        //     debugger
        // }
        if (Array.isArray(obj[k])) {
          if (Array.isArray(data[k])) {
            obj[k] = data[k]
          } else {
            try {
              let tmp = JSON.parse(data[k])
              if (tmp != null) {
                obj[k] = tmp
              }
            } catch (error) {
              console.error('json parse error', k, error)
            }
          }
        } else {
          obj[k] = data[k]
        }
      }
    }
    return obj
  }
}
